package com.qwc.blog.web.admin;

import cn.hutool.cache.impl.CacheObj;
import cn.hutool.cache.impl.TimedCache;
import com.qwc.blog.common.annotation.AdminController;
import com.qwc.blog.common.constant.ConfigConstant;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * @author qiuwencong
 * @Date 2022/2/7 15:34
 * @Package com.qwc.blog.web.admin.common
 * @Description
 */
@Slf4j
@AdminController("/cache")
public class CacheController {

    @Autowired
    private TimedCache<String, String> cache;

    @RequestMapping("/list")
    public List<Object> cacheList(){
        Iterator<CacheObj<String, String>> cacheObjIterator = cache.cacheObjIterator();
        List<Object> list = new ArrayList<>();
        if (cacheObjIterator.hasNext()) {
            CacheObj<String, String> next = cacheObjIterator.next();
            list.add(next);
        }
        cache.get(ConfigConstant.TOKEN);
        return list;
    }
}
